﻿using Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;

namespace Utilities.Tests
{
    [TestClass()]
    public class TextFileProcessorTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void TextFileProcessorProcessTest()
        {
            int lines = 1;

            TextFileProcessor processor = new TextFileProcessor
            {
                Path = @"..\..\..\Utilities.Tests\Text\TextFileProcessorTestFile.txt",
                OnCharacter = (reader, pos, c) =>
                {
                    Debug.WriteLine("Character: '" + c + "' found at position: " + pos);
                    Debug.WriteLine("Next character: '" + reader.Peek() + "'");

                    return true;
                },
                OnEndOfLine = (reader, pos, eol) =>
                {
                    Debug.WriteLine("New line found at position: " + pos);
                    Debug.WriteLine("Next character: '" + reader.Peek() + "'");

                    ++lines;

                    return true;
                }
            };

            processor.Process();

            Assert.AreEqual(4, lines);
            Assert.AreEqual(9, processor.Characters);

            Debug.WriteLine("Elapsed time: " + processor.ElapsedTime);
        }
    }
}
